/*
 * Ebeno0.java
 *
 * Created on 25 listopad 2007, 22:27
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package pla.bib;

//import java.awt.Point;
import javax.vecmath.Point3d;
import odc.Odcinek;

/**
 *
 * @author arkadiusz
 */
public class Ebeno3D // implements Comparable<Ebeno3D>
{
  double A;
  double B;
  double C;
  double D;
  Odcinek oA;
  Odcinek oB;
  
  /**
   * Creates a new instance of Ebeno3D
   */
  public Ebeno3D(double a, double b, double c, double d) {
    this.A = a;
    this.B = b;
    this.C = c;
    this.D = d;
  }
   
  public Ebeno3D(Odcinek a, Odcinek b){
    this.oA = a;
    this.oB = b;
    
    this.ABCD(a,b);
    
  }
  
  double normo(){
    return Math.sqrt(A*A+B*B+C*C);
  }
  
  public void normu(){
    double n = this.normo();
    this.A /=n;
    this.B /=n;
    this.C /=n;
    this.D /=n;
  }
  
  public Point3d[] getPoint3d() {
    return new Point3d[]{
      new Point3d(oA.x1,oA.y1,oA.z1),
      new Point3d(oA.x2,oA.y2,oA.z2),
      new Point3d(oB.x2,oB.y2,oB.z2),
      new Point3d(oB.x1,oB.y1,oB.z1)
      
    };
  }
  
  public void korektu(Ebeno3D eb) {
    Odcinek a = this.oA;
    Odcinek b = eb.oA;
    
    this.ABCD(a,b);
    
    this.oA = a;
    this.oB = b;
  }
  
  public String toString(){
    this.normu();
    return "[" + this.A + ";"+ this.B + ";"+ this.C + ";"+ this.D + "]";
    //return "[" +
  }
  
  private void ABCD(Odcinek a, Odcinek b){
    
    double w[]  = a.razyW(b);
    //sirodek ciezkosci
    double x0 = (a.x1 + a.x2 + b.x1 + b.x2)/4.0;
    double y0 = (a.y1 + a.y2 + b.y1 + b.y2)/4.0;
    double z0 = (a.z1 + a.z2 + b.z1 + b.z2)/4.0;
    //srednia po czterech plaszczyznach
    this.A = w[0];
    this.B = w[1];
    this.C = w[2];
    //this.D =  - w.razySD(new WektorD3D(x0,y0,z0) ) ;
    this.D = - x0 * this.A - y0 * this.B - z0 * this.C;
    if(Double.isNaN(this.D) ){
      System.out.println("NaN");
    }
    
  }
  
  
  public Double getD(){
    return this.D;
  }
  
  public Point3d[] getOdcinekA(){
    return new Point3d[]{
      new Point3d(oA.x1,oA.y1,oA.z1),
      new Point3d(oA.x2,oA.y2,oA.z2),
      
    };
  }
  public Point3d[] getOdcinekB(){
      return new Point3d[]{
      new Point3d(oB.x2,oB.y2,oB.z2),
      new Point3d(oB.x1,oB.y1,oB.z1)
      
    };
  }
}
